package com.cw.controller;

import cn.hutool.core.bean.BeanUtil;
import com.cw.common.R;
import com.cw.entity.OrderDetail;
import com.cw.entity.dto.ReportResponseTemplate;
import com.cw.service.OrderDetailService;
import com.cw.service.OrdersService;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Nice_BernardShaw
 * @date 2023/3/23 15:56
 */
@RestController
@RequestMapping("/statistic")
public class OrderStatisticController {
    @Resource
    private OrdersService ordersService;
    @Resource
    private OrderDetailService orderDetailService;
    @Resource
    private RedisTemplate redisTemplate;

    @GetMapping("/monthlyReport")
    public R monthlyReport() {
        if (BeanUtil.isNotEmpty(redisTemplate.opsForValue().get("monthlyReport"))) {
            return R.success(redisTemplate.opsForValue().get("monthlyReport"));
        }
        List<ReportResponseTemplate> monthlyReport = this.ordersService.monthlyReport();

        return R.success(monthlyReport);
    }
    @GetMapping("/dishRank")
    public R dishRank(){
        List<ReportResponseTemplate> list = this.orderDetailService.dishRank();
        return R.success(list);
    }
    @GetMapping("/setmealRank")
    public R setmealRank(){
        return  R.success(this.orderDetailService.setmealRank());
    }
    @GetMapping("/dailySaleData")
    public R DailySaleData(){

        ReportResponseTemplate reportResponseTemplate = new ReportResponseTemplate();
        reportResponseTemplate.setName("当日营业额");
        if (BeanUtil.isEmpty(this.orderDetailService.dailySaleData())){
            reportResponseTemplate.setValue(0);
        }else {
            reportResponseTemplate.setValue(this.orderDetailService.dailySaleData());
        }
        return  R.success(reportResponseTemplate);
    }
    @GetMapping("/dailyFood")
    public R dailyFood(){

        List<ReportResponseTemplate> list = this.orderDetailService.dailyFood();
        return R.success(list);
    }
    @GetMapping("/favoriteWindow")
    public R favoriteFood(){

        List<ReportResponseTemplate> list = this.orderDetailService.favoriteWindow();
        return R.success(list);
    }
}